const httpUtils = require('../../../utils/httpUtils')
const ui = require('../../../utils/ui')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: -1,
    showTextAndTitleWithInput: false,
    expenseBill: {}
  },
  //查询消费单详情
  getExpenseDetail: function () {
    let that = this;
    let id = that.data.id;
    let obj = {
      method: 'GET',
      showLoading: false,
      url: 'expenseBill/getExpenseById?id=' + id
    }
    httpUtils.request(obj).then(res => {
      console.log(res.data.message)
      if (res.data.retCode == 0) {
        this.setData({
          expenseBill: res.data.data
        })
      } else {
        ui.showToast(res.data.message)
      }
    }).catch(err => {
      ui.showToast('请求失败')
    });
  },

  //点击删除弹窗的确定
  confirmChange: function (e) {
    let that = this;
    let id = that.data.id;
    let obj = {
      method: 'GET',
      showLoading: false,
      url: 'expenseBill/delExpense?id=' + id
    }
    httpUtils.request(obj).then(res => {
      if (res.data.retCode == 0) {
        ui.showToast('保存成功')
        wx.navigateBack({
          detail: 1
        })
      } else {
        ui.showToast(res.data.message)
      }
    }).catch(err => {
      ui.showToast('请求失败')
    });
  },

  //点击删除弹窗的取消
  closeDialog: function () {
    this.setData({
      ['showTextAndTitleWithInput']: false
    });
  },

  //点击了删除按钮
  onDelete: function (e) {
    let item = e.currentTarget.dataset.entity;
    this.setData({
      ['showTextAndTitleWithInput']: true,
      item: item
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      id: options.id
    })
    this.getExpenseDetail();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getExpenseDetail();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})